package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.model.product.SpuImage;
import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Trump
 * @Date: 2025/8/20 14:30
 * @Description:
 **/
@Api(tags = "商品sku接口")
@RestController
@RequestMapping("/admin/product")
public class SkuManageController {

    @Autowired
    private ManageService manageService;
    //根据SpuId查询spuImageList


    @GetMapping("spuImageList/{spuId}")
    public Result<List<SpuImage>> getSpuImageList(@PathVariable("spuId")Long spuId){
        List<SpuImage> spuImageList=   manageService.getSpiImageList(spuId);

         return Result.ok(spuImageList);

    }

    @GetMapping("spuSaleAttrList/{spuId}")
    public Result<List<SpuSaleAttr>> getSpusaleAttrList(@PathVariable("spuId")Long spuId){

        List<SpuSaleAttr> spuSaleAttrList= manageService.getSpuSaleAttrList(spuId);
        return Result.ok(spuSaleAttrList);

    }




    @GetMapping("/list/{page}/{limit}")
    public Result index(@PathVariable Long page,@PathVariable Long limit){
        Page<SkuInfo> skuInfoPage = new Page<>(page,limit);
        IPage<SkuInfo> pageSku = manageService.getPage(skuInfoPage);
        return Result.ok(pageSku);
    }


    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable("skuId") Long skuId){
        manageService.onSale(skuId);
        return Result.ok();
    }
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){
        manageService.cancelSale(skuId);
        return Result.ok();
    }

    @GetMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
         manageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }



}
